package com.itheima.demo1;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Scanner;

public class Demo {

    public static void main(String[] args) throws SocketException {
        Scanner sc =new Scanner(System.in);

        DatagramSocket bs = bs = new DatagramSocket();
        String s = null;
        System.out.println("发送端输入:");
        while (true) {
            try {

                s = sc.next();

                if(s.equals("over"))break;

                InetAddress byName = InetAddress.getByName("127.0.0.1");
                 byte[] bytes = s.getBytes();
                DatagramPacket dp = new DatagramPacket(bytes,bytes.length,byName,10086);

                bs.send(dp);
            } catch (IOException e) {
            e.printStackTrace();
            }
        }
        bs.close();
    }
}
